#!/bin/bash

mkdir -p t || exit 1
cd t || exit 1
checkrev()
{
	if [ ! -d "$1" ]; then
		svn co "$2" "$1" || exit 1
	else
		cd "$1" || exit 1
		svn up || exit 1
		cd .. || exit 1
	fi

	cd "$1" || exit 1
	r="`svn info | sed -e '/^Revision:/s/^Revision:[ ]*//p;d'`"
	if [ "$?" != "0" ]; then
		exit 1
	fi
	cd .. || exit 1

	if [ "$r" -lt "$3" ]; then
		echo "$1 rev $r is older than in this repository? how is that possible?"
		exit 1
	fi
	if [ "$r" == "$3" ]; then
		exit 0
	fi
	echo "$1 rev $r is newer than in this repository - update needed (but you will have to manually commit)"
	echo -n "press ENTER to continue (or Ctrl-C to abort):"
	read
	tar cf - --exclude '.svn' "$1" | tar xf - -C ..
	rv="$?"
	if [ "$rv" != "0" ]; then
		echo "tar exited with code $rv"
		exit 1
	fi
}

checkrev unbound-svn http://unbound.nlnetlabs.nl/svn/trunk/ 2109 || exit 1
checkrev jabberd2-svn http://codex.xiaoka.com/svn/jabberd2/trunk/ 890 || exit 1

echo "success: this file has comments on how to merge to trunk"
#
# the final steps are to merge the updated branch into the trunk:
#
# example for unbound-svn:
# 1. cd branches/unbound-svn
#
# 2. svn ci -m "import unbound svn rev NNN from http://unbound.nlnetlabs.nl/svn/trunk"
# it will commit and tell you what the commit number is: NNN
#
# 3. svn merge -c NNN . ../../trunk/unbound-svn
# # use -c <commit number> from the last step
# # the merge probably won't just automatically work, so take care of conflicts, etc.
#
# 4. cd ../../trunk
#
# 5. svn stat
# # examine what has come down the pipe from unbound-svn
#
# 6. ./bootstrap.sh
# # fix all remaining conflicts, get it to build correctly
#
# 7. test the changes thoroughly
#
# 8. commit changes to trunk
#
